/* 
 * ProjectFile: message-broker\src\api\sso.js
 * Created: lijianwei 2022-06-02 23:17:37
 * -----
 * LastModified: lijianwei 2023-01-10 10:49:36
 * -----
 * Copyright (c) 2016-2023 Rongwen Tech Ltd.
 * -----
 */

import request from "request-client"
import config from "../config.cjs"
const { AppConfig } = config

/**
 * 用户信息
 */
export function getUserInfo(data, options) {
    return new Promise((resolve, reject) => {
        request({
            url: AppConfig.domainBaseService + '/' + AppConfig.ssoUrlProfix + '/v1/admin/mine/index',
            method: "post",
            body: data,
            headers: Object.assign({
                "content-type": "application/json;charset=utf-8",
                "user-agent": 'BackendApp-InstantMsg/' + AppConfig.appId,
            }, options.headers || {}),
        }, (nullVal, response, data) => {
            AppConfig.ENV_DEBUG && console.log('[Response - UserInfo]', data)
            let res;
            try {
                res = JSON.parse(data)
                resolve(res);
            } catch (error) {
                console.error('[Response - getUserInfo] JSON.parse - err', error.message)
                reject(error.message)
            }
        });
    });

}

/**
 * 设备信息 - 暂无用
 */
export function getDeviceInfo(data, options) {
    return new Promise((resolve, reject) => {
        request({
            url: AppConfig.domainBaseService + '/' + AppConfig.ssoUrlProfix + '/v1/admin/mine/index',
            method: "post",
            body: data,
            headers: Object.assign({
                "content-type": "application/json;charset=utf-8",
                "user-agent": 'BackendApp-InstantMsg/' + AppConfig.appId,
            }, options.headers || {}),
        }, (nullVal, response, data) => {
            AppConfig.ENV_DEBUG && console.log('[Response - DeviceInfo]', data)
            let res;
            try {
                res = JSON.parse(data)
                resolve(res);
            } catch (error) {
                console.error('[Response - getDeviceInfo] JSON.parse - err', error.message)
                reject(error.message)
            }
        });
    });

}
